﻿/*   */
$(function () {
    initRightTenCaseCount();//局长主页右侧十个案件数量
    initChartsView_ajbar();//案件页面 案件柱状图
    function initChartsView_ajbar() {
        let dom = document.getElementById('chartsView_ajbar');
        let myChart = echarts.init(dom, null, {
            renderer: 'canvas',
            useDirtyRect: false
        });
        CoreUtil.sendPost("/statistics/indexAjxxZztNew", null, function (res) {
            let dataScope = res.data.dataScope;
            let qj = res.data.qj;
            let k1 = res.data.k1;
            let k2 = res.data.k2;
            let k3 = res.data.k3;
            let k4 = res.data.k4;
            let k5 = res.data.k5;
            let kssj = res.data.kssj;

            let jcj_option = {
                legend: {},
                tooltip: {},
                dataset: {
                    dimensions: ['product', '在查', '在审', '在执行', '中止检查', '办结'],
                    source: [
                        ['product', '在查', '在审', '在执行', '中止检查', '办结'],
                        qj, k1, k2, k3, k4, k5, kssj
                    ]
                }, toolbox: {
                    show: true,
                    feature: {
                        dataView: {show: true, readOnly: true, title: '表格显示', lang: ['本局数据：', '关闭']},
                        magicType: {show: true, type: ['line', 'bar'], title: {line: '折线图', bar: '柱状图'}}
                    }
                },
                xAxis: {type: 'category'},
                yAxis: {},
                series: [{type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}]
            };

            let sysj_option = {
                legend: {},
                tooltip: {},
                dataset: {
                    dimensions: ['product', '在查', '在审', '在执行', '中止检查', '办结'],
                    source: [
                        ['product', '在查', '在审', '在执行', '中止检查', '办结'],
                        qj, k1, k2, k3, k4
                    ]
                }, toolbox: {
                    show: true,
                    feature: {
                        dataView: {show: true, readOnly: true, title: '表格显示', lang: ['本市数据：', '关闭']},
                        magicType: {show: true, type: ['line', 'bar'], title: {line: '折线图', bar: '柱状图'}}
                    },
                    optionToContent: function (opt) {
                        console.log(opt);
                        let axisData = opt.dataset[0].source;
                        let series = opt.dataset[0].dimensions;
                        let tdHeaders = '<td></td>'; //表头
                        for (let i = 1; i <= series.length - 1; i++) {
                            tdHeaders += '<td>' + series[i] + '</td>'; //组装表头
                        }
                        let table = '<div class="table-responsive"><table class="table table-bordered table-striped table-hover" style="text-align:center"><tbody><tr>' + tdHeaders + '</tr>';
                        let tdBodys = ''; //数据
                        for (let i = 1, l = axisData.length - 1; i <= l; i++) {
                            let sjdata = axisData[i];
                            let trtmp = "<tr>";
                            for (let j = 0; j < sjdata.length; j++) {
                                tdBodys += '<td style="padding: 0 10px">' + sjdata[j] + '</td>';
                            }
                            tdBodys = trtmp + tdBodys + "</tr>"
                        }
                        table += tdBodys + '</tbody></table></div>';
                        return table;
                    }
                },
                xAxis: {type: 'category'},
                yAxis: {},
                series: [{type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}]
            };


            if (dataScope === "jcj") {
                myChart.setOption(jcj_option);
                $("#showAjxxBarTitle").text("本局案件");
            } else if (dataScope === "all") {
                myChart.setOption(sysj_option);
                $("#showAjxxBarTitle").text("本市案件");
            }
        });
        window.addEventListener('resize', myChart.resize);
    }

    function initRightTenCaseCount() {
        //获取token
        //地址栏转义token中的#号
        let $ = jQuery = layui.jquery;
        CoreUtil.sendPost("/attention/initRightTenCaseCount", null, function (res) {
            let sncaajs = res.data.SNCAAJS;
            let bnxzajs = res.data.BNXZAJS;
            let zcajajs = res.data.ZCAJAJS;
            let zzajajs = res.data.ZZAJAJS;
            let zsajajs = res.data.ZSAJAJS;
            let bnsjajs = res.data.BNSJAJS;
            let zxajajs = res.data.ZXAJAJS;
            let bnjaajs = res.data.BNJAAJS;
            let bjajajs = res.data.BJAJAJS;
            let ajyjajs = res.data.AJYJAJS;
            //上年存案数
            $("#snca").text(sncaajs);
            //本年新增案件数
            $("#bnxz").text(bnxzajs);
            //在查案件数
            $("#zcaj").text(zcajajs);
            //中止案件数
            $("#zzaj").text(zzajajs);
            //在审案件数
            $("#zsaj").text(zsajajs);
            //本年审结案件数
            $("#bnsj").text(bnsjajs);
            //执行案件数
            $("#zxaj").text(zxajajs);
            //本年结案案件数
            $("#bnja").text(bnjaajs);
            //办结案件数
            $("#bjaj").text(bjajajs);
            //案件预警
            $("#ajyj").text(ajyjajs);
        });
    }
});

function switchCaseBarToTable() {
    let div1 = document.getElementById("chartsView_ajbar");
    if (div1.style.display === "none") {
        div1.style.display = "block";
        const collection = document.getElementsByName("container");
        for (let i = 0; i < collection.length; i++) {
            if (collection[i].tagName === "DIV") {
                collection[i].style.display = "none";
            }
        }
    } else {
        $("#container2_tbody").empty(); // 清空原有数据
        CoreUtil.sendPost("/statistics/anyuanAndanjian", {"swjgDm": ""}, function (res) {
            let tableDatas = res.data.tableDatas;
            let tableHjDatas = res.data.tableHjDatas;//合计行
            let dataScope = res.data.dataScope;
            $.each(tableDatas, function (index, item) {
                let swjgmcTD = "";
                let rowHtml = "";
                if ("all" === dataScope) {
                    swjgmcTD = "<td style='text-align: center'>" +
                        '<a href="javascript:void(0);" style="color:darkorchid" onclick=' +
                        '"xiazuan(3,' + item.SWJGDM + ',' + "'swjgmc'" + ',' + "'2'" + ')">' +
                        item.SWJGMC + "</a></td>";
                    rowHtml = "<tr>" +
                        // <a href="javascript:void(0);" style="color:black" onclick="xiazuanQ(1)" ;>稽查局</a>
                        swjgmcTD
                        + "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(21,' + item.SWJGDM + ',' + "'snjc'" + ',' + "'2'" + ')">' + item.SNJCSL + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(21,' + item.SWJGDM + ',' + "'bnxz'" + ',' + "'2'" + ')">' + item.BNXZSL + "</td><td style='text-align: center;color:black'>" + item.AYHJ + "</td>" +
                        "<td style='text-align: center'>" + '<a  class="adisabled"href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(3,' + item.SWJGDM + ',' + "'jc'" + ',' + "'2'" + ')">' + item.BNJCSL + "</td><td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(3,' + item.SWJGDM + ',' + "'sl'" + ',' + '2' + ')">' + item.BNSLSL + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(3,' + item.SWJGDM + ',' + "'zx'" + ',' + "'2'" + ')">' + item.BNZXSL + "</td><td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(3,' + item.SWJGDM + ',' + "'bj'" + ',' + "'2'" + ')">' + item.BNBJSL + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(3,' + item.SWJGDM + ',' + "'ja'" + ',' + "'2'" + ')">' + item.BNJASL + "</td><td style='text-align: center;color:black'>" + item.AJZS + "</td>" +
                        "<td style='text-align: center;color:black'>" + item.NSRHSSL + "</td>" +
                        "</tr>";
                } else if ("jcj" === dataScope) {
                    swjgmcTD = "<td style='text-align: center'>" +
                        '<a href="javascript:void(0);" style="color:darkorchid" onclick=' +
                        '"xiazuan(4,' + item.SWJGDM + ',' + "'swjgmc'" + ',' + "'3'" + ')">' +
                        item.SWJGMC + "</a></td>";
                    rowHtml = "<tr>" +
                        // <a href="javascript:void(0);" style="color:black" onclick="xiazuanQ(1)" ;>稽查局</a>
                        swjgmcTD
                        + "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(21,' + item.SWJGDM + ',' + "'snjc'" + ',' + "'3'" + ')">' + item.SNJCSL + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(21,' + item.SWJGDM + ',' + "'bnxz'" + ',' + "'3'" + ')">' + item.BNXZSL + "</td><td style='text-align: center;color:black'>" + item.AYHJ + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(4,' + item.SWJGDM + ',' + "'jc'" + ',' + "'3'" + ')">' + item.BNJCSL + "</td><td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(4,' + item.SWJGDM + ',' + "'sl'" + ',' + "'3'" + ')">' + item.BNSLSL + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(4,' + item.SWJGDM + ',' + "'zx'" + ',' + "'3'" + ')">' + item.BNZXSL + "</td><td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(4,' + item.SWJGDM + ',' + "'bj'" + ',' + "'3'" + ')">' + item.BNBJSL + "</td>" +
                        "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                        '"xiazuan(4,' + item.SWJGDM + ',' + "'ja'" + ',' + "'3'" + ')">' + item.BNJASL + "</td><td style='text-align: center;color:black'>" + item.AJZS + "</td>" +
                        "<td style='text-align: center;color:black'>" + item.NSRHSSL + "</td>" +
                        "</tr>";
                }
                $("#container2_tbody").append(rowHtml);
            });
            //合计行
            let hjData = tableHjDatas[0];
            const hjrowhtml = "<tr>"
                + "<td style='text-align: center'>合计</td>"
                + "<td style='text-align: center;color:black'>" + hjData.snjctotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.bnxztotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.hjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.jctotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.sltotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.zxtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.bjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.jatotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.ajzstotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.hstotal + "</td>"
                + "</tr>";
            $("#container2_tbody").append(hjrowhtml);
        });


        div1.style.display = "none";
        const collection = document.getElementsByName("container");
        for (let i = 0; i < collection.length; i++) {
            if (collection[i].tagName === "DIV") {
                collection[i].style.display = "none";
            }
        }
        let div2 = document.getElementById("container2");
        div2.style.display = "block";
    }

    //container2--案件页面一级表格
    //container3--一级表格点击-税务机关名称（二级）
    //container21--一级表格点击--数字（二级）
    //container4--container3点击税务机关名称（三级）显示人
}

/**
 *
 * @param bianhao 是 div id数字  4=三级 3=二级  21 是点击数字二级
 * @param type 是点击的类别 swjgmc=点击税务机关名称   数字点击为：snjc=上年结存  bnxz=本年新增  jc sl zx bj ja
 * @param swjgDm 是点击所属税务机关代码
 * @param level 判断是几级下钻 2 是要查2级  3 是要查3级
 */

function xiazuan(bianhao, swjgDm, type, level) {
    // if (bianhao === 4) {
    //     alert('功能暂不可用！');
    //     return false;
    // }
    // if(type !='back'){
    //     // || (type === 'swjgmc' && level == '3')
    //     if (type != 'swjgmc' ) {
    //         alert('功能暂不可用！');
    //         return false;
    //     }
    // }
    if (level === '3') {
        $("#container4_tbody").empty(); // 清空原有数据
        CoreUtil.sendPost("/statistics/anyuanAndanjian_swry", {"swjgDm": swjgDm}, function (res) {
            let tableDatas = res.data.tableDatas;
            let tableHjDatas = res.data.tableHjDatas;//合计行
            $.each(tableDatas, function (index, item) {
                let swrymcTD = "<td style='text-align: center'>" + item.SWRYXM + "</td>";
                let rowHtml = "<tr>" +
                    swrymcTD
                    + "<td style='text-align: center'>" + '<a  href="javascript:void(0);" style="color:darkorchid" onclick=' +
                    '"showAjxx(' + item.SWRYDM +"," + item.JCBMDM + ',' + item.BNJCSL + ',2' + ')">' + item.BNJCSL + "</td><td style='text-align: center'>" + '<a href="javascript:void(0);" style="color:darkorchid" onclick=' +
                    '"showAjxx('  + item.SWRYDM +"," + item.JCBMDM + ',' + item.BNSLSL + ',3' +  ')">' + item.BNSLSL + "</td>" +
                    "<td style='text-align: center'>" + '<a  href="javascript:void(0);" style="color:darkorchid" onclick=' +
                    '"showAjxx(' + item.SWRYDM +"," + item.JCBMDM + ',' + item.BNZXSL + ',4' +  ')">' + item.BNZXSL + "</td><td style='text-align: center'>" + '<a  href="javascript:void(0);" style="color:darkorchid" onclick=' +
                    '"showAjxx(' + item.SWRYDM +"," + item.JCBMDM + ',' + item.BNBJSL+ ',901'  +  ')">' + item.BNBJSL + "</td>" +
                    "<td style='text-align: center'>" + '<a  href="javascript:void(0);" style="color:darkorchid" onclick=' +
                    '"showAjxx(' + item.SWRYDM +"," + item.JCBMDM + ',' + item.BNJASL + ',5'  + ')">' + item.BNJASL + "</td><td style='text-align: center;color:black'>" + item.AJZS + "</td>" +
                    "</tr>";
                $("#container4_tbody").append(rowHtml);
            });
            //合计行
            let hjData = tableHjDatas[0];
            const hjrowhtml = "<tr>"
                + "<td style='text-align: center'>合计</td>"
                + "<td style='text-align: center;color:black'>" + hjData.jctotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.sltotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.zxtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.bjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.jatotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.ajzstotal + "</td>"
                + "</tr>";
            $("#container4_tbody").append(hjrowhtml);
        });
    } else {
        if (level === '2') {
            $("#container3_tbody").empty(); // 清空原有数据
        } else if (level === '3') {
            $("#container4_tbody").empty(); // 清空原有数据
        }
        CoreUtil.sendPost("/statistics/anyuanAndanjian", {"swjgDm": swjgDm}, function (res) {
            let tableDatas = res.data.tableDatas;
            let dataScope = res.data.dataScope;
            let tableHjDatas = res.data.tableHjDatas;//合计行
            $.each(tableDatas, function (index, item) {
                let swjgmcTD = "";
                let rowHtml = "";
                swjgmcTD = "<td style='text-align: center'>" +
                    '<a href="javascript:void(0);" style="color:darkorchid" onclick=' +
                    '"xiazuan(4,' + item.SWJGDM + ',' + "'swjgmc'" + ',' + "'3'" + ')">' +
                    item.SWJGMC + "</a></td>";
                rowHtml = "<tr>" +
                    // <a href="javascript:void(0);" style="color:black" onclick="xiazuanQ(1)" ;>稽查局</a>
                    swjgmcTD
                    + "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(21,' + item.SWJGDM + ',' + "'snjc'" + ',' + "'3'" + ')">' + item.SNJCSL + "</td>" +
                    "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(21,' + item.SWJGDM + ',' + "'bnxz'" + ',' + "'3'" + ')">' + item.BNXZSL + "</td><td style='text-align: center;color:black'>" + item.AYHJ + "</td>" +
                    "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(4,' + item.SWJGDM + ',' + "'jc'" + ',' + "'3'" + ')">' + item.BNJCSL + "</td><td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(4,' + item.SWJGDM + ',' + "'sl'" + ',' + "'3'" + ')">' + item.BNSLSL + "</td>" +
                    "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(4,' + item.SWJGDM + ',' + "'zx'" + ',' + "'3'" + ')">' + item.BNZXSL + "</td><td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(4,' + item.SWJGDM + ',' + "'bj'" + ',' + "'3'" + ')">' + item.BNBJSL + "</td>" +
                    "<td style='text-align: center'>" + '<a class="adisabled" href="javascript:void(0);" style="color:black" onclick=' +
                    '"xiazuan(4,' + item.SWJGDM + ',' + "'ja'" + ',' + "'3'" + ')">' + item.BNJASL + "</td><td style='text-align: center;color:black'>" + item.AJZS + "</td>" +
                    "<td style='text-align: center;color:black'>" + item.NSRHSSL + "</td>" +
                    "</tr>";
                // }
                if (level === '2') {
                    $("#container3_tbody").append(rowHtml);
                } else if (level === '3') {
                    $("#container4_tbody").append(rowHtml);
                }
            });
            //合计行
            let hjData = tableHjDatas[0];
            const hjrowhtml = "<tr>"
                + "<td style='text-align: center'>合计</td>"
                + "<td style='text-align: center;color:black'>" + hjData.snjctotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.bnxztotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.hjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.jctotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.sltotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.zxtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.bjtotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.jatotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.ajzstotal + "</td>"
                + "<td style='text-align: center;color:black'>" + hjData.hstotal + "</td>"
                + "</tr>";
            if (level === '2') {
                $("#container3_tbody").append(hjrowhtml);
            } else if (level === '3') {
                $("#container4_tbody").append(hjrowhtml);
            }
        });
    }


    let div1 = document.getElementById("chartsView_ajbar");
    const collection = document.getElementsByName("container");
    for (let i = 0; i < collection.length; i++) {
        if (collection[i].tagName === "DIV") {
            collection[i].style.display = "none";
        }
    }
    div1.style.display = "none";
    let containerId = "container" + bianhao;
    let divTemp = document.getElementById(containerId);
    divTemp.style.display = "block";
}

function showAjxx(swryDm, swjgDm, sl,ajztDm) {
    if (sl === 0) {
        alert("当前选中数量为0！");
        return false;
    }
    let title = "";
    if(ajztDm === 2){
        title = "检查";
    }else if(ajztDm === 3) {
        title = "审理";
    }else if(ajztDm === 4) {
        title = "执行";
    }else if(ajztDm === 901) {
        title = "办结";
    }else if(ajztDm === 5) {
        title = "结案";
    }
    skipOpen("/index/statistics/anjianxiazhuan?swryDm=" + swryDm+"&swjgDm="+swjgDm+"&ajztDm="+ajztDm, "11001", title);
}